﻿package mortal.game.view.copy.worldBoss.WorldBossAllot
{
    import Message.Client.*;
    import Message.Public.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.game.cache.*;

    public class WorldBossAllotCellData extends EventDispatcher
    {
        public var isInit:Boolean = false;
        public var bossCode:int;
        public var itemCode:int;
        public var status:int;
        public var isSelf:Boolean;
        public var startDate:Date;
        public var signNum:int;
        public var diceList:Array;
        public var isDiced:Boolean;
        public var getterPlayerName:String;
        public var getterDiceNum:int;
        public var selfDiceNum:int;

        public function WorldBossAllotCellData()
        {
            this.diceList = [];
            return;
        }// end function

        public function copyFromInfo(param1:SGuildItemBetUpdateInfo, param2:int) : void
        {
            var _loc_3:String = null;
            var _loc_5:int = 0;
            var _loc_6:SGuildItemDiceResult = null;
            var _loc_7:SGuildItemDiceUpdateInfo = null;
            this.bossCode = param1.bossCode;
            this.itemCode = param2;
            this.status = param1.status;
            this.isSelf = param1.myItemCodes && param1.myItemCodes.indexOf(this.itemCode) > -1;
            this.startDate = param1.starDt;
            this.signNum = param1.applyInfo[this.itemCode];
            var _loc_4:* = int(Cache.instance.vip.getTVipConfigByType(EVipRecordType._EVipRecordTypeWorldBossSice));
            _loc_4 = _loc_4 > 1 ? (_loc_4) : (1);
            this.isDiced = param1.myItemCodes && param1.myItemCodes.length >= _loc_4;
            if (!this.isInit && this.diceList.length == 0 && param1.diceInfo)
            {
                _loc_5 = 0;
                while (_loc_5 < param1.diceInfo.length)
                {
                    
                    _loc_6 = param1.diceInfo[_loc_5];
                    if (_loc_6.itemCode == this.itemCode)
                    {
                        _loc_7 = new SGuildItemDiceUpdateInfo();
                        _loc_7.bossCode = param1.bossCode;
                        _loc_7.itemCode = this.itemCode;
                        _loc_7.playerName = _loc_6.playerName;
                        _loc_7.dice = _loc_6.dice;
                        if (_loc_6.playerId == Cache.instance.role.entityInfo.entityId.id)
                        {
                            this.selfDiceNum = _loc_6.dice;
                            this.diceList.unshift(_loc_7);
                        }
                        else
                        {
                            this.diceList.push(_loc_7);
                        }
                    }
                    _loc_5++;
                }
            }
            this.getterDiceNum = 0;
            this.getterPlayerName = Language.getString(21449);
            if (this.status == EWorldBossAllotStatus._EEnd)
            {
                _loc_5 = 0;
                while (_loc_5 < param1.diceInfo.length)
                {
                    
                    _loc_6 = param1.diceInfo[_loc_5];
                    if (_loc_6.itemCode == this.itemCode)
                    {
                        if (_loc_6.dice > this.getterDiceNum)
                        {
                            this.getterPlayerName = _loc_6.playerName;
                            this.getterDiceNum = _loc_6.dice;
                        }
                    }
                    _loc_5++;
                }
            }
            this.isInit = true;
            if (this.status == EWorldBossAllotStatus._EEnd)
            {
                this.dispatchEvent(new Event(Event.CHANGE));
            }
            return;
        }// end function

        public function addPlayerDiceMsg(param1:SGuildItemDiceUpdateInfo) : void
        {
            if (param1.playerName == Cache.instance.role.entityInfo.name)
            {
                this.diceList.unshift(param1);
            }
            else
            {
                this.diceList.push(param1);
            }
            if (param1.playerName == Cache.instance.role.entityInfo.name)
            {
                this.selfDiceNum = param1.dice;
            }
            this.dispatchEvent(new Event(Event.CHANGE));
            return;
        }// end function

    }
}
